package test;

import java.util.Arrays;

public class test1 {

    public static void duplicateZeros(int[] arr) {
        int k=-1;
        int i=0;
        for(;i<arr.length;i++){
            if(arr[i]==0){
                k++;
            }
            k++;
            if(k>=arr.length-1){
                break;
            }
        }
        if(k==arr.length){
            arr[--k]=arr[i--];
            k--;
        }

        for(;i>=0;i--){
            if(arr[i]==0){
                arr[k--]=0;
                arr[k--]=0;
            }else{
                arr[k--]=arr[i];
            }
        }
    }

    public static void main(String[] args) {
int[]arr={1,0,2,3,0,4,5,0};
duplicateZeros(arr);
        System.out.println(Arrays.toString(arr));
    }

}
